<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
	template="/WEB-INF/layouts/standard.xhtml" 
	xmlns:a4j="http://richfaces.org/a4j" 
	xmlns:rich="http://richfaces.org/rich"
	xmlns:bf="http://www.bssmanager.com/jsf"
	xmlns:c="http://java.sun.com/jstl/core">

	<ui:define name="formheader">
		<h2>Beds</h2>
	</ui:define>
	
	<ui:define name="formGlobal">
		<bf:dateSelector controller="#{bedController}"  date="date" ajaxUpdate="false"/>
	</ui:define>
	
	
	<ui:define name="content">

		<c:set var="controller" value="${bedController}" />
		<h:messages errorClass="errors" style="color:#ff1111" />

		<h:form id="#{controller.modelName}">
			<h:panelGrid columns="3">				
				<h:outputLabel value="Building:" />				
				<rich:comboBox
							value="#{controller.building}"
							suggestionValues="#{buildingController.all}"
							converter="#{buildingConverter}">
							<a4j:support event="onchange" reRender="bedRooms"
															status="statusC1"/>								
				</rich:comboBox>
				<a4j:status forceId="true" id="statusC1" >
					 <f:facet name="start">
		                  <h:graphicImage value="/images/im1.gif"/>
		             </f:facet>
				</a4j:status>
				<h:outputLabel value="Room" />
				<rich:comboBox id="bedRooms" value="#{controller.model.room}" suggestionValues="#{controller.rooms}"
					converter="#{roomConverter}">
					<a4j:support event="onchange" reRender="bedRateTxt"
															status="statusC2"/>
				</rich:comboBox>
				<a4j:status forceId="true" id="statusC2" >
					 <f:facet name="start">
		                  <h:graphicImage value="/images/im1.gif"/>
		             </f:facet>
				</a4j:status>
				<h:outputLabel value="Bed Type:" />
				<rich:comboBox value="#{controller.model.bedType}" suggestionValues="#{bedTypeDao.all}"
					converter="#{bedTypeConverter}">
				</rich:comboBox>
				<h:outputLabel value="" />
				<h:outputLabel value="Bed Number:" />
				<c:choose>
					<c:when test="#{controller.editing}">
						<h:outputText value="#{controller.model.bedNumber}" />
					</c:when>
					<c:otherwise>
						<h:inputText value="#{controller.model.bedNumber}" />
					</c:otherwise>
				</c:choose>
				
				<h:outputLabel value="" />
				<h:outputLabel value="Rate**:" />
				<h:outputText id="bedRateTxt" value="#{controller.model.room.rate}" />
							
				<h:outputLabel value="" />
				<h:panelGroup>
					<h:commandButton disabled="#{controller.editing}" id="submit" action="#{controller.add}" value="Add" />&#160;
					<h:commandButton disabled="#{!controller.editing}" action="#{controller.update}" value="Update" />&#160;
					<h:commandButton id="cancel" value="Cancel" action="#{controller.cancel}" />
				</h:panelGroup>
				<h:outputLabel value="" />
				<h:outputLabel value="** Room rate is considered as bed rate in case of dormitory" />
			</h:panelGrid>

			<rich:dataTable value="${controller.data}" var="aBean" align="center">
				<f:facet name="header">
					<h:panelGrid columns="3">
						<h:outputText value="All #{controller.modelName}s" />
					</h:panelGrid>
				</f:facet>
				<rich:column>
					<f:facet name="header">
						<h:outputText value="Edit" />
					</f:facet>
					<h:commandButton style="width:15px;height:15px;#{controller.editing ? 'cursor: not-allowed':''}"
						title="#{controller.editing ? 'Edit already in progress...':'Click to Edit'}" image="/resrc/images/edit1.jpg"
						disabled="#{controller.editing}" action="${controller.select}" />
				</rich:column>
				<rich:column  >
					<f:facet name="header">
						<h:outputText value="Delete" />
					</f:facet>
					<h:commandButton
						title="#{controller.editing ? 'Edit is in progress, please complete the editing...':'Click to Delete'}"
						image="/resrc/images/trash.gif" style="width:15px;height:15px;#{controller.editing ? 'cursor: not-allowed':''}"
						disabled="#{controller.editing}" action="${controller.remove}" immediate="true"
						onclick="if(!showConfirmation('Are you sure to remove #{controller.modelName}: #{aBean.bedNumber} from Room #{aBean.room.roomNumber} - ?')) return false;" />
				</rich:column>
				<rich:column>
					<f:facet name="header">Bed Number</f:facet>
					<h:outputText value="#{aBean.bedNumber}" />
				</rich:column>
				<rich:column>
					<f:facet name="header">Room</f:facet>
					<h:outputText value="#{aBean.room.roomNumber}" />
				</rich:column>
				<rich:column>
					<f:facet name="header">Dormitory</f:facet>
					<h:outputText value="#{aBean.room.dormitory ? 'Yes' : ''}" />
				</rich:column>
				<rich:column>
					<f:facet name="header">Rate</f:facet>
					<h:outputText value="#{aBean.room.rate}" />
				</rich:column>
				<c:if test="#{controller.data.rowCount le 0}">
					<f:facet name="footer">
						<h:outputText value="No #{controller.modelName}s available..." />
					</f:facet>
				</c:if>
			</rich:dataTable>
		</h:form>
	</ui:define>
</ui:composition>